<?php
/**
 * auth_groups.inc
 * Template: Administrate auth groups.
 * @copyright	Copyright(c) 2002-2010 Bjorn Winberg
 * @author		Bjorn Winberg <cms@anomalye.net>
 * @license		http://www.gnu.org/licenses/gpl.html GNU General Public License version 2
 */
	$this->mSystem->mHtmlHeaders[] = '<link type="text/css" href="' . $this->getSkinUrl('auth_groups.css') . '" rel="stylesheet" />';
?>
<h1><?php echo $this->localString('G_TITLE');?></h1>
<div class="helpBox">
	<?php 
		echo $this->localString('G_HELP');
	?>
</div>

<div class="authGroupsUserSection">
<?php
	$rowStyle = 'sectionRow1';
	echo '<div class="sectionHeader">';
	if($aParams['groupId'] !== false){
		echo '<div class="authUsersCol authUsersColTitle">' . $this->localString('G_USERS_FILTER', array($this->getSafeStr($aParams['groupName']))) . '</div>';
		$rowStyle = 'authGroupsRowFilterYes';
	}
	else{
		echo '<div class="authUsersCol authUsersColTitle">' . $this->localString('G_USERS') . '</div>';
	}
	echo '</div>';
	foreach($aParams['users'] as $userId => $userName){
		echo '<div class="' . $rowStyle . '">';
		echo '<div class="authUsersCol authUsersColName"><a href="' . $this->generateUrl('auth', array('a' => 'groups', 'user_id' => $userId, 'offset' => $this->pagingOffset())) . '">' . $this->getSafeStr($userName) . '</a></div>';
		echo '<div class="authUsersCol authUsersColDelete">[<a href="' . $this->generateUrl('auth', array('a' => 'delete_user', 'user_id' => $userId, 'offset' => $this->pagingOffset())) . '">' . $this->localString('G_DELETE_USER') . '</a>]</div>';
		echo '</div>';
	}
	echo $this->pagingGenerateFooter($aParams['usersPrev'], $aParams['usersNext']);
?>
</div>


<div class="authGroupsGroupSection">
<?php
	$addGroupForm = '<form class="inlineForm" id="auth_addGroupForm" action="' . $this->generateUrl('auth', array('a' => 'add_group')) . '" method="post">';
	$addGroupForm .= '<input type="text" id="name" name="name" value="" maxlength="' . Auth::PARAM_MAX_NAME . '" />';
	$addGroupForm .= '<input type="submit" name="submit" value="' . $this->localString('G_GROUP_SUBMIT') . '" /></form>';
	echo '<div class="sectionHeader">';
	if($aParams['userId'] !== false){
		echo '<div class="authGroupsCol authGroupsColTitle">' . $this->localString('G_GROUPS_FILTER', array($this->getSafeStr($aParams['userName']))) . '</div>';
	}
	else{
		echo '<div class="authGroupsCol authGroupsColTitle">' . $this->localString('G_GROUPS') . '</div>';
	}
	echo '<div class="authGroupsCol authGroupsColForm">' . $addGroupForm . '</div>';
	echo '</div>';
	foreach($aParams['groups'] as $groupId => $groupName){
		$grantButtons = false;
		$rowStyle = 'sectionRow1';
		if($aParams['userId'] !== false){
			if(isset($aParams['userGroups'][$groupId])){
				$rowStyle = 'authGroupsRowFilterYes';
				$grantButtons = '<div class="authGroupsCol authGroupsColKick">[<a href="' . $this->generateUrl('auth', array('a' => 'kick_user', 'group_id' => $groupId, 'user_id' => $aParams['userId'])) . '">' . $this->localString('G_DELETE_USER_GROUP', array($this->getSafeStr($aParams['userName']))) . '</a>]</div>';
			}
			else{
				$rowStyle = 'authGroupsRowFilterNo';
				$grantButtons = '<div class="authGroupsCol authGroupsColJoin">[<a href="' . $this->generateUrl('auth', array('a' => 'join_user', 'user_id' => $aParams['userId'], 'group_id' => $groupId)) . '">' . $this->localString('G_JOIN_USER_GROUP', array($this->getSafeStr($aParams['userName']))) . '</a>]</div>';
			}
		}
		echo '<div class="' . $rowStyle . '">';
		echo '<div class="authGroupsCol authGroupsColName"><a href="' . $this->generateUrl('auth', array('a' => 'groups', 'group_id' => $groupId)) . '">' . $this->getSafeStr($groupName) . '</a></div>';
		echo $grantButtons;
		echo '<div class="authGroupsCol authGroupsColDelete">[<a href="' . $this->generateUrl('auth', array('a' => 'delete_group', 'group_id' => $groupId)) . '">' . $this->localString('G_DELETE_GROUP') . '</a>]</div>';
		echo '</div>';
	}
?>
</div>

<div class="authGroupsActionSection">
<?php
	$addActionForm = '<form class="inlineForm" id="auth_addActionForm" action="' . $this->generateUrl('auth', array('a' => 'add_action')) . '" method="post">';
	$addActionForm .= '<input type="text" id="name" name="name" value="" maxlength="' . Auth::PARAM_MAX_NAME . '" />';
	$addActionForm .= '<input type="submit" name="submit" value="' . $this->localString('G_ACTION_SUBMIT') . '" /></form>';
	echo '<div class="sectionHeader">';
	if($aParams['groupId'] !== false){
		echo '<div class="authActionsCol authActionsColTitle">' . $this->localString('G_ACTIONS_FILTER', array($this->getSafeStr($aParams['groupName']))) . '</div>';
	}
	else if($aParams['userId'] !== false){
		echo '<div class="authActionsCol authActionsColTitle">' . $this->localString('G_ACTIONS_FILTER', array($this->getSafeStr($aParams['userName']))) . '</div>';
	}
	else{
		echo '<div class="authActionsCol authActionsColTitle">' . $this->localString('G_ACTIONS') . '</div>';
	}
	echo '<div class="authActionsCol authActionsColForm">' . $addActionForm . '</div>';
	echo '</div>';
	foreach($aParams['actions'] as $actionId => $actionName){
		$grantButtons = false;
		$groupParents = false;
		$rowStyle = 'sectionRow1';
		if($aParams['groupId'] !== false){
			if(isset($aParams['groupActions'][$actionId])){
				$rowStyle = 'authGroupsRowFilterYes';
				$grantButtons = '<div class="authActionsCol authActionsColRevoke">[<a href="' . $this->generateUrl('auth', array('a' => 'revoke_action', 'group_id' => $aParams['groupId'], 'action_id' => $actionId)) . '">' . $this->localString('G_DELETE_GROUP_ACTION', array($this->getSafeStr($aParams['groupName']))) . '</a>]</div>';
			}
			else{
				$rowStyle = 'authGroupsRowFilterNo';
				$grantButtons = '<div class="authActionsCol authActionsColGrant">[<a href="' . $this->generateUrl('auth', array('a' => 'grant_action', 'action_id' => $actionId, 'group_id' => $aParams['groupId'])) . '">' . $this->localString('G_GRANT_ACTION', array($this->getSafeStr($aParams['groupName']))) . '</a>]</div>';
			}
		}
		if($aParams['userId'] !== false){
			if(isset($aParams['userGroupActions'][$actionId])){
				$rowStyle = 'authGroupsRowFilterYes';
				$groupParents = '<div class="authActionsCol authActionsColParents">{ ';
				foreach($aParams['userGroupActions'][$actionId] as $index => $group){
					$groupParents .= $group . ' ';
				}
				$groupParents .= '}</div>';
			}
			else{
				$rowStyle = 'authGroupsRowFilterNo';
			}
		}
		echo '<div class="' . $rowStyle . '">';
		echo '<div class="authActionsCol authActionsColName">'. $this->getSafeStr($actionName) . '</div>';
		echo $grantButtons;
		echo $groupParents;
		echo '<div class="authActionsCol authActionsColDelete">[<a href="' . $this->generateUrl('auth', array('a' => 'delete_action', 'action_id' => $actionId)) . '">' . $this->localString('G_DELETE_ACTION') . '</a>]</div>';
		echo '</div>';
	}
?>
</div>
